#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import pprint
import codecs
import pymongo

pp = pprint.PrettyPrinter()

autocomplete_words_object = codecs.open("/root/coreseek-4.1-beta/testpack/etc/pysource/csft_pymongo/data/autocomplete_keywords_list.txt","r","utf-8")

'''init mongodb database connection'''
connection = pymongo.Connection('localhost', 27017)
db = connection.news.autocomplete_kw

kid = 1

for i in autocomplete_words_object:
    autocomplete_kw_record = {'id':kid,'words':i,'hits':1}
    pp.pprint(autocomplete_kw_record)
    db.insert(autocomplete_kw_record)
    kid += 1

db.close()